package cn.siat.gene.controller;

import cn.siat.common.core.web.controller.BaseController;
import cn.siat.common.core.web.domain.AjaxResult;
import cn.siat.common.core.web.page.TableDataInfo;
import cn.siat.common.log.annotation.Log;
import cn.siat.common.log.enums.BusinessType;
import cn.siat.gene.domain.GenomeData;
import cn.siat.gene.domain.ProgrammeFile;
import cn.siat.gene.domain.ProgrammeFlieMinio;
import cn.siat.gene.domain.dto.GenomeDataDto;
import cn.siat.gene.domain.dto.GenomeDataQueryParam;
import cn.siat.gene.domain.dto.ProgrammeFileDto;
import cn.siat.gene.domain.dto.ProgrammeFileQueryParam;
import cn.siat.gene.domain.vo.GenomeDataVO;
import cn.siat.gene.domain.vo.ProgrammeFileVO;
import cn.siat.gene.service.IGenomeDataService;
import cn.siat.gene.service.IProgrammeFileService;
import cn.siat.gene.service.IProgrammeFlieMinioService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: 基因组数据信息
 * @Author: mingwei
 * @Date: 2023-7-23
 * @Version: V1.0
 */
@Api(tags = "基因组数据信息")
@RestController
@RequestMapping("/programmeFile")
@Slf4j
public class ProgrammeFileController extends BaseController {
    @Autowired
    private IProgrammeFileService programmeFileService;
    /**
     * 分页列表查询
     *
     * @return
     */
    @Log(title = "基因组数据查询", businessType = BusinessType.VIEWED)
    @ApiOperation(value = "基因组数据查询", notes = "基因组数据查询")
    @GetMapping(value = "/list")
    public TableDataInfo queryPageList(ProgrammeFileQueryParam queryParams) {
        startPage();
        List<ProgrammeFileVO> pageList = programmeFileService.queryPageList(queryParams);
        return getDataTable(pageList);
    }
    /**
     * 获取标签列表
     * @return
     */
    @GetMapping("/listTab")
    public AjaxResult listTab(){
        return AjaxResult.success(programmeFileService.listTab());
    }
    /**
     * 删除基因组数据
     */
    @Log(title = "基因组数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    public AjaxResult removeGenomeData(@RequestBody ProgrammeFile programmeFile)
    {
        return toAjax(programmeFileService.deleteProgrammeFileById(programmeFile));
    }
    /**
     * 新增基因组数据
     */
    @Log(title = "基因组数据", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult saveGenomeData(@RequestBody ProgrammeFileDto programmeFileDto)
    {
        return AjaxResult.success(programmeFileService.insertProgrammeFile(programmeFileDto));
    }


    @GetMapping("/percentage")
    public AjaxResult getPercentage(String md5){
        String percentage = programmeFileService.getPercentage(md5);
        return AjaxResult.success("成功",percentage);
    }
    /**
     * 修改文件
     */
    @Log(title = "基因组数据", businessType = BusinessType.INSERT)
    @PostMapping("/update")
    public AjaxResult updateProgrammeFile(@RequestBody ProgrammeFileDto programmeFileDto)
    {
        return toAjax(programmeFileService.updateProgrammeFile(programmeFileDto));
    }
    /**
     * 修改基因组数据状态
     */
    @Log(title = "基因组数据", businessType = BusinessType.INSERT)
    @PostMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody ProgrammeFile programmeFile)
    {
        programmeFile.setUpdateTime(new Date());
        return toAjax(programmeFileService.updateById(programmeFile));
    }

    /**
     * 根据minio_file md5查询minio文件id
     *
     * @return
     */
    @ApiOperation(value = "根据minio_file md5查询minio文件id", notes = "根据minio_file md5查询minio文件id")
    @GetMapping(value = "/getMinioFileIds")
    public AjaxResult queryMinioFileIds(String[] minioFileMd5Str) {
        Long[] ids = programmeFileService.queryMinioFileIds(minioFileMd5Str);
        return AjaxResult.success(ids);
    }

    /**
     * 分页列表查询
     *
     * @return
     */
    @Log(title = "基因组数据查询", businessType = BusinessType.VIEWED)
    @ApiOperation(value = "基因组数据查询", notes = "基因组数据查询")
    @GetMapping(value = "/fileList")
    public TableDataInfo queryUploadFileList(ProgrammeFileQueryParam queryParams) {
        startPage();
        return getDataTable(programmeFileService.queryUploadFileList(queryParams));
    }
//    /**
//     * 修改基因组数据
//     */
//    @Log(title = "基因组数据", businessType = BusinessType.INSERT)
//    @PostMapping("/update")
//    public AjaxResult updateGenomeData(@RequestBody GenomeDataDto genomeDataDto)
//    {
//        return toAjax(genomeDataService.updateGenomeData(genomeDataDto));
//    }
//    /**
//     * 修改基因组数据状态
//     */
//    @Log(title = "基因组数据", businessType = BusinessType.INSERT)
//    @PostMapping("/updateStatus")
//    public AjaxResult updateGenomeDataStatus(@RequestBody Map<String,String> map)
//    {
//        return toAjax(genomeDataService.updateGenomeDataStatus(map));
//    }
//
//    /**
//     * 校验名称(已存在返回true)
//     * @param name
//     * @return
//     */
//    @GetMapping("/checkName")
//    public AjaxResult checkName(String name,String id){
//        Boolean isExist = genomeDataService.checkName(name,id);
//        return AjaxResult.success(isExist);
//    }
//
//    /**
//     * 根据minio_file md5查询minio文件id
//     *
//     * @return
//     */
//    @ApiOperation(value = "根据minio_file md5查询minio文件id", notes = "根据minio_file md5查询minio文件id")
//    @GetMapping(value = "/getMinioFileIds")
//    public AjaxResult queryMinioFileIds(String minioFileMd5Str) {
//        Long[] ids = genomeDataService.queryMinioFileIds(minioFileMd5Str);
//        return AjaxResult.success(ids);
//    }
}
